﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Permissions;
using System.Web.Services.Description;
using System.Collections.Generic;
using System.Web.Configuration;

public partial class AccountInfo : Basepage
{
    //khoi tao ket noi csdl
    static string strconn = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(strconn);
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void UpdateButton_Click(object sender, EventArgs e)
    {
         string url = this.Page.Request.Url.AbsoluteUri;//get the url of current page
        try
        {
            con.Open();
            string username = Request.Cookies["username"].Value;
            if (Password.Text.Trim() != "")
            {

                string updateComm = "UPDATE ThanhVien SET MatKhau=N'" + Password.Text.Trim() + "' WHERE TenDangNhap='" + username + "'";
                SqlCommand comm = new SqlCommand(updateComm, con);
                comm.ExecuteNonQuery();
            }
            if (FullName.Text.Trim() != "")
            {
                string updateComm = "UPDATE ThanhVien SET HoTen=N'" + FullName.Text.Trim() + "' WHERE TenDangNhap='" + username + "'";
                SqlCommand comm = new SqlCommand(updateComm, con);
                comm.ExecuteNonQuery();
            }
            if (Email.Text.Trim() != "")
            {
                string updateComm = "UPDATE ThanhVien SET DiaChi=N'" + Email.Text.Trim() + "' WHERE TenDangNhap='" + username + "'";
                SqlCommand comm = new SqlCommand(updateComm, con);
                comm.ExecuteNonQuery();
            }
            if (UserType.SelectedValue.Trim() != "")
            {
                string updateComm = "UPDATE ThanhVien SET LoaiTK=N'" + UserType.SelectedValue.Trim() + "' WHERE TenDangNhap='" + username + "'";
                SqlCommand comm = new SqlCommand(updateComm, con);
                comm.ExecuteNonQuery();
            }
            if (PhoneNumber.Text.Trim() != "")
            {
                string updateComm = "UPDATE ThanhVien SET DienThoai=N'" + PhoneNumber.Text.Trim() + "' WHERE TenDangNhap='" + username + "'";
                SqlCommand comm = new SqlCommand(updateComm, con);
                comm.ExecuteNonQuery();
            }
            if (CardID.Text.Trim() != "")
            {
                string updateComm = "UPDATE ThanhVien SET MaTheThanhToan=N'" + CardID.Text.Trim() + "' WHERE TenDangNhap='" + username + "'";
                SqlCommand comm = new SqlCommand(updateComm, con);
                comm.ExecuteNonQuery();
            }
            if (url.Contains("lang=vi"))
            {
                lbMessage.Text = "Cập nhật thành công! ";
            }
            else
            {
                lbMessage.Text = "Update success!";
            }
            con.Close();
        }
        catch (Exception)
        {
            
            if (url.Contains("lang=vi"))
            {
                lbMessage.Text = "Cập nhật thất bại! ";
            }
            else
            {
                lbMessage.Text = "Update Fail!";
            }
            con.Close();
        }


    }
}